/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xrkol.sharelib.dao.LeaveRequestDao;
import com.xrkol.sharelib.entity.Clazz;
import com.xrkol.sharelib.entity.LeaveRequest;
import com.xrkol.sharelib.service.LeaveRequestService;
import com.google.common.collect.Lists;

/**
 * @author peng.xia
 *
 */
@Service
@Transactional
public class LeaveRequestServiceImpl implements LeaveRequestService{

    @Autowired
    private LeaveRequestDao leaveRequestDao;
    
    @Override
    public void save(LeaveRequest entity) {
        this.leaveRequestDao.save(entity);
    }

    @Override
    public void update(LeaveRequest entity) {
        this.leaveRequestDao.update(entity);
    }

    @Override
    public void delete(String id) {
        this.leaveRequestDao.delete(id);
    }

    @Override
    public LeaveRequest findById(String id) {
        return this.leaveRequestDao.findById(id);
    }

    @Override
    public List<LeaveRequest> getLeaveRequestByClazz(Clazz clazz,Integer page) {
        return this.leaveRequestDao.getLeaveRequestByClazz(clazz,page);
    }

    @Override
    public List<LeaveRequest> getLeaveRequestsByClasses(List<Clazz> clazzs) {
        List<LeaveRequest> allLeaveRequests=Lists.newArrayList();
        for (Clazz clazz : clazzs) {
            List<LeaveRequest> leaveRequests = this.leaveRequestDao.getLeaveRequestByClazz(clazz);
            allLeaveRequests.addAll(leaveRequests);
        }
        return allLeaveRequests;
    }

}
